package com.example.demo.Controller;

import com.example.demo.Dto.AddressDto;
import com.example.demo.Dto.AddressUpdateDto;
import com.example.demo.Service.AddressService;
import com.example.demo.result.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
//地址相关接口
@RestController
@RequestMapping("/api/v1/addresses")
public class AddressesController {
    @Autowired
    private AddressService addressService;

    /**
     * 添加地址信息
     * @param addressDto
     * @return
     */
    @PostMapping()
    public ResponseResult add(@RequestBody AddressDto addressDto){
        addressService.add(addressDto);
        return new ResponseResult().ok("200","地址添加成功");
    }

    /**
     *获取地址信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseResult getAll(@PathVariable Long id){
       return new ResponseResult().ok("200","获取地址信息成功",addressService.getAll(id));
    }

    /**
     * 删除地址信息
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult Delectaddresses(@PathVariable Long id){
        addressService.delect(id);
        return new ResponseResult().ok(200,"地址删除成功",null);
    }
    /**
     * 修改地址信息
     * @param addressUpdateDto
     * @return
     */
    @PutMapping
    public ResponseResult updateaddresses(@RequestBody AddressUpdateDto addressUpdateDto){
        addressService.updateAddress(addressUpdateDto);
        return new ResponseResult().ok(200,"地址修改成功",null);
    }
    /**
     * 获取某个用户所有地址信息
     * @return
     */
    @GetMapping
    public ResponseResult getAlladdresses(@RequestParam Integer pageNum, @RequestParam Integer pageSize){
        return new ResponseResult().ok(200,"获取所有地址信息成功",addressService.getAlladdresses(pageSize, pageNum));
    }
}
